package cn.tedu.yl.root.service.impl;

import cn.tedu.yl.root.mapper.RootMapper;
import cn.tedu.yl.root.pojo.dto.RootQuery;
import cn.tedu.yl.root.pojo.dto.RootSaveParam;
import cn.tedu.yl.root.pojo.entity.Root;
import cn.tedu.yl.root.pojo.vo.RootVO;
import cn.tedu.yl.root.service.RootService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Slf4j
@Service
public class RootServiceImpl implements RootService {
    @Autowired
    private RootMapper rootMapper;
    @Override
    public void save(RootSaveParam rootSaveParam) {
        Root root=new Root();
        BeanUtils.copyProperties(rootSaveParam,root);
        if (root.getId() ==null){
        rootMapper.insertRoot(root);
        }else {
            rootMapper.updateRoot(root);
        }
    }

    @Override
    public List<RootVO> select(RootQuery rootQuery) {
        log.info("查询参数:{}",rootQuery);
        List<RootVO> rootVOS = rootMapper.selectRoot(rootQuery);
        log.info("查询结果:{}",rootVOS);
        return rootVOS;

    }
}
